<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/pages/safeai/jsp/common/taglibs.jsp"%>
<html>
<head>
<title>录入订单</title>
		<%@ include file="/pages/safeai/jsp/common/meta.jsp"%>
		<script type="text/javascript" src="${ctx}/script/common/common.js"></script>
		<script type="text/javascript" src="${ctx}/script/jquery-1.2.3.min.js"></script>
		<script type="text/javascript" src="${ctx}/script/order1.js"></script>
		<script type='text/javascript' src='${ctx}/js/Ajax.js'></script>
		<script type='text/javascript' src='${ctx}/dwr/engine.js'></script>
		<script type='text/javascript' src='${ctx}/dwr/util.js'></script>
		<link href="${ctx}/css/safeai/together.css" rel="stylesheet" type="text/css">
		<STYLE type=text/css>
.delMouseOver {
	BACKGROUND: #d0e0ff;
	COLOR: black;
	CURSOR: hand;
	FONT-FAMILY: verdana, arial, helvetica;
	FONT-SIZE: 14px;
}

.scheduleButtonVisible {
	BACKGROUND: silver;
	BORDER-BOTTOM: gray 1px dashed;
	BORDER-LEFT: white 1px dashed;
	BORDER-RIGHT: gray 1px dashed;
	BORDER-TOP: white 1px dashed;
	COLOR: black;
	CURSOR: hand;
	FONT-FAMILY: verdana, arial, helvetica;
	FONT-SIZE: 14px;
}
.STYLE1 {color: #FF0000}
        </STYLE>

</head>
	<body style="font-size: 12px">
		<%@ include file="/pages/safeai/jsp/common/taglibs.jsp"%>
	<form action="${ctx}/addBillManage.do?method=saveBill" method="post" name="orderIndexForm" id="orderForm">
<table width="99%" align="center">
<input type=hidden id=freeDeliver value="0"/>
				<tr>
					<th colspan="5" height="25px">
						录入订单
					</th>
				</tr>
				<tr>
					
					<td class="td_3">
						录入人
					：</td>
					<td class="td_04">
						<bean:write name="USERINFO" property="username" />
					</td>
					<td bgcolor="#CCCCCC" >&nbsp;</td>
	  <td class="td_3">
						客户留言
					：</td>
					<td  class="td_04">
					<textarea name="orderindex.customerword"  cols="35" rows="4" onchange="return checkLen(this);"></textarea>						
					</td>
				</tr>
				<tr>
					<td class="td_3">
						订货人用户名
					：</td>
					<td class="td_04">
						<input type="text" name="orderindex.username" id="u2" readonly/>
					</td>
					<td bgcolor="#cccccc" align="center">
					
						</td>
					<td class="td_3">
					</td>
					<td class="td_04">						
					</td>
				</tr>
				<tr>
					<input type="hidden" name="orderindex.customerid" id="id" />
					<td class="td_3">
						订单人VIP卡号
					：</td>
					<td class="td_04">
						<input type="text" name="orderindex.vipcode" id="v2" readonly/>
						
					</td >
						<td bgcolor="#cccccc" align="center">
						<a href="#" onclick="allover()"> >>>> </a>
						</td>
					<input type="hidden" name="password2" id="pas2" value="rayi" />
					<td class="td_3">
						<span class="STYLE1">*</span>收货人城市
					：</td>
					<td class="td_04">
					   省：<select name="orderindex.provinces" id="provinces"></select>市：<select name="orderindex.citys" id="citys"></select>区：<select name="orderindex.villages" id="villages"></select>
						
					</td>
				</tr>
				<tr>
					<td class="td_3">
						订货人
					：</td>
					<td class="td_04">
						<input type="text" name="orderindex.customername" id="n2" readonly/>
					</td>
				<td bgcolor="#CCCCCC" align="center">
						<a href="#" onclick="overn()"> >> </a>						</td>
	  <td class="td_3">
					<span class="STYLE1">*</span>	收货人
					：</td>
					<td class="td_04">
						<input type="text" id="orderindexConsignee"
							name="orderindex.consignee" maxlength="50"/>&nbsp;&nbsp;&nbsp;
						<a href="customerManage.do?method=serachforHistoryByCondition"
							target="_blank" id="addShr"
							onclick="return setuid(document.getElementById('id').value,document.getElementById('addShr'))">修改收货人</a>

					</td>

				</tr>
				<tr>
					<td class="td_3">
						订货人地址
					：</td>
					<td class="td_04">
						<input type="text" name="address2" id="a2" readonly/>
					</td>
					<td bgcolor="#CCCCCC" align="center">
						<a href="#" onclick="overa()"> >> </a>						</td>					
	  <td class="td_3">
						<span class="STYLE1">*</span>收货人地址
					：</td>
					<td class="td_04">
						<input type="text" id="orderindexAddress"
							name="orderindex.address" maxlength="255"/>
					</td>

				</tr>
				<tr>
					<td class="td_3">
						订货人邮编
					：</td>
					<td class="td_04">
						<input type="text" name="postcode2" id="p2" readonly/>
					</td>
					<td bgcolor="#CCCCCC" align="center">
						<a href="#" onclick="overp()"> >> </a>						</td>
	  <td class="td_3">
					<span class="STYLE1">*</span>	收货人邮编
					：</td>
					<td class="td_04">
						<input type="text" id="orderindexPostcode"
							name="orderindex.postcode" maxlength="50"/>
					</td>

				</tr>
				<tr>
					<td class="td_3">
						订货人手机
					：</td>
					<td class="td_04">
						<input type="text" name="mobilephone2" id="ph2" readonly/>
					</td>
					<td bgcolor="#CCCCCC" align="center">
						<a href="#" onclick="overph()"> >> </a>						</td>
	  <td class="td_3">
						<span class="STYLE1">*</span>收货人手机
					：</td>
					<td class="td_04">
						<input type="text" id="orderindexMobilephone"
							name="orderindex.mobilephone" maxlength="255"/>
					</td>
				</tr>
				
				<tr>
					<td class="td_3">
						订货人固定电话
					：</td>
					<td class="td_04">
						<input type="text" name="phone2" id="h2" readonly/>
					</td>
					<td bgcolor="#CCCCCC" align="center">
						<a href="#" onclick="overh()"> >> </a>						</td>
	  <td class="td_3">
						收货人固定电话
					：</td>
					<td class="td_04">
						<input type="text" id="orderindexPhone"
							name="orderindex.phone" maxlength="255"/>
					</td>
				</tr>
				
				<tr>
					<td class="td_3">
						订货人邮箱
					：</td>
					<td class="td_04">
						<input type="text" name="email2" id="e2" readonly/>
					</td>
					<td bgcolor="#CCCCCC" align="center">
						<a href="#" onclick="overe()"> >> </a>						</td>
	  <td class="td_3">
						<span class="STYLE1">*</span>收货人邮箱
					：</td>
					<td class="td_04">
						<input type="text" id="orderindexEmail"
							name="orderindex.email" maxlength="255"/>
					</td>
				</tr>

				<tr>
					<td class="td_3">
						<span class="STYLE1">*</span>付款方式	：				</td>
					<td class="td_04">
						<select name="orderindex.paymentid" id="payment">
							
							
						</select>
					</td>
					<td bgcolor="#CCCCCC">&nbsp;</td>
      				<td class="td_3">
						<span class="STYLE1">*</span>配送方式	：				</td>
					<td class="td_04">
						<select name="orderindex.deliverid" id="deliver" onchange="newOpenerDeliverChange()" >
							
							
						</select>
					</td>
	</tr>
	<tr>
					<td class="td_3">
						发票类型
					：</td>
					<td colspan="4" class="td_04">
					<select name="orderindex.invoicetype" id="invoicetype" >
					<option selected="selected" value="1">
										普通发票										
									</option>
					<option  value="2">
										增值税发票 
									</option>
					<option  value="3">
										无发票类型 
									</option>
					</select>
					</td>

				</tr>
				<tr>
					<td class="td_3">
						发票抬头
					：</td>
					<td colspan="4" class="td_04">
						<textarea name="orderindex.invoicecompany" cols="60" rows="2" onchange="return checkLen(this);"></textarea>
					</td>

				</tr>
				<tr>
					<td class="td_3">
						发票内容
					：</td>
					<td colspan="4" class="td_04">
						<textarea name="orderindex.invoicecontent" cols="60" rows="4" onchange="return checkLen(this);"></textarea>
					</td>

				</tr>

			</table>
			<br>
	  <table  borderColorDark="gray" borderColorLight="silver" id="PLList" width="99%">
				<TBODY>
				  <tr>
					<th width="18px" id=tdt class="td_01">
							<FONT color=white><a href="javascript:delAll()">删除全部</a> <INPUT
									name=deid type=hidden> <INPUT name=edit type=hidden>
							</FONT>
					</th>
						<th class="td_01">
							物品
					</th>
						<th class="td_01">
							备注
					</th>
						<th class="td_01">
							<INPUT name=price type=hidden>
							单价
					</th>
						<th class="td_01">
							<INPUT name=isspecialoffer type=hidden>
							是否开发票
					</th>

						<th class="td_01">
							<INPUT name=count type=hidden>
							数量
					</th>
						<th class="td_01">
							<INPUT name=cash type=hidden>
							金额
					</th>
					</tr>
				</TBODY>
	  </table>
			<SCRIPT>
allCount=1
</SCRIPT>
		<table borderColorDark=gray borderColorLight=silver width="99%" id="pont">       	
			<tr>
					<td align="right" class="td_02">
					可用积分：
                <input border="0" type="text" id="paypoint"  value="0" readonly>
                &nbsp; &nbsp; &nbsp; &nbsp;
                 
						支付积分：
					  <input border="0" type="text" id="paypoint1" name="orderindex.usepoint"
							value="0" onChange="reCash3();" maxlength="11">
					</td>
		  </tr>
				<tr>
					<td align="right" class="td_02">
					可用滞留金：
                    <input border="0" type="text" id="paycash" value="0" readonly>
                     &nbsp; &nbsp; &nbsp; &nbsp;
						支付滞留金：
					  <input border="0" type="text" id="paycash1" name="orderindex.usebalance"
							value="0" onChange="reCash3();" maxlength="10">
					</td>
				</tr> 
				<tr>				
					<td align="right" class="td_02">
					使用优惠卷：
                    <input border="0" type="text"  name="orderindex.usetickettype"  id="ecoId"/>
                    <input type="hidden" id="ecouponPrice"/>
                    <input type="button" value="使用" class="btn" onclick="return userEco();" style="border: 1 solid #000000" />
                    <input type="button" value="取消" class="btn" onclick="return unuserEco();" style="border: 1 solid #000000" />
                     &nbsp; &nbsp; &nbsp; &nbsp;
						配送金额：
						<input border="0" type="text" id="delivercash" name="orderindex.needcarriage"
							onChange="reCash3();" maxlength="10">
						<input type="hidden" id="tagdeliver"/>
					</td>
				</tr>
				<tr>			
					<td align="right" class="td_02">
						合计金额：
						<input border="0" type="text" id="allcashId" value="0" name="allcash" readonly>
						<input type="hidden" id="needpay" name="orderindex.needpay">
					</td>
					<input type="hidden" name="temp" id="temp" value="1">
				</tr>
	  </table>
	  <table width="99%">
		<tr>
		  <td align="center">
			<input type="button" class="btn" value="添加新产品(录入库中没有的产品)" onclick="newHospitalVisit()">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="hidden"/ name="orderindex.cityId" id="c1">
			<input type="hidden"/ name="orderindex.historyId" id="historyId">
			<input type="submit" value="录入订单" class="btn" onclick="return check();" style="border: 1 solid #000000" />
		  </td>
		</tr>
	  </table>
		</form><br /> 
			<table id="table2" width="99%" align="center">
				<tr>
					<td>
						商品名称模糊查询：					</td>
					<td>
						用户名模糊查询：					</td>
					<td>
						vip卡号查询：					</td>
					<td>
						姓名查询：					</td>
				</tr>
                <tr>
                	<form action="${ctx}/customerManage.do?method=serachforProduct" method="post">
                		<td class="td_02">
                    		<input type="text" name="catalogs.pname"/>&nbsp;
						  	<input type="submit" value="搜索" class="btn" onclick="show('customerManage.do?method=serachforProduct');"/>                    
						</td>
				    </form>
					<form action="${ctx}/customerManage.do?method=serachforName" method="post" target="_blank">
                   	 	<td class="td_02">
                   	 		<input type="text" name="customer.username" />&nbsp;
                    		<input type="submit" value="搜索" class="btn"/>
                    	</td>
                    </form>	
                      	
                    <form action="${ctx}/customerManage.do?method=serachforName" method="post" target="_blank">
                    	<td class="td_02">
                    		<input type="text" name="customer.vip" />&nbsp;
							<input type="submit" value="搜索" class="btn"/>                  
						</td>
					</form>
						
					<form action="${ctx}/customerManage.do?method=serachforName" method="post" target="_blank">
                    	<td class="td_02">
                    		<input type="text" name="customer.realName" />&nbsp;
							<input type="submit" value="搜索" class="btn"/>                   
						</td>
					</form>
                </tr>
			</table>

	</body>
</html>
<script language="javascript">

    window.onload=function(){//onload start    
    //************************城市级联开始**********************************
       //省
       var provinces=document.getElementById("provinces");
       //市
       var citys=document.getElementById("citys");
       //区
       var villages=document.getElementById("villages");
       
       getProvinces();
       getCitys();
       getVillages();
       
       provinces.onchange=function(){
           getCitys();
           getVillages(); 
           villages.onchange();
       }
       citys.onchange=function(){
           getVillages();
           villages.onchange();
       }
       
       villages.onchange=function(){ 
          newOpenerCitySelect(villages.value);
          newOpenerDeliverChange();
       }
       
       villages.onchange();
       
    }//onload end
    function getProvinces(){
    var ajax=new Ajax();
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getAllProvince","get",backProvince);
    }
    
    function backProvince(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("provinces");

	    DWRUtil.addOptions("provinces", list);
    }
    
    function getCitys(){
        var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getCitys&provinceName="+encodeURI(provinceName),'get',backCity);
    }
    
    function backCity(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("citys");
	    DWRUtil.addOptions("citys", list);
    }
    
    function getVillages(){
    var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var citys=document.getElementById("citys");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        var cityName=citys.options[citys.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/order/cityOreder.do","method=getVillages&provinceName="+encodeURI(provinceName)+"&cityName="+encodeURI(cityName),'get',backVillage);
    }
    
    function backVillage(str){
        var list=str.split(",");
        DWRUtil.removeAllOptions("villages");
	    DWRUtil.addOptions("villages", list);
	    if(str=="请选择,"){
	    	document.getElementById("deliver").options.length = 0;
	    	document.getElementById("deliver").options.add(new Option("请选择", "999"));
	    	document.getElementById("payment").options.length = 0;
			document.getElementById("payment").options.add(new Option("请选择", "999"));
					}
    }
    
    //************************城市级联结束**********************************
    function newOpenerCitychange(msg) {

   		if (msg != null && msg != "NULL") {
   		
   					document.getElementById("deliver").options.length = 0;
					document.getElementById("payment").options.length = 0;
				
					var d = msg.split(" ")[0];
					var p = msg.split(" ")[1];
					var postCode = msg.split(" ")[2];
					document.getElementById("orderindexPostcode").value = postCode;

					var d1 = d.split(",");
					var p1 = p.split(",");

					for (i = 0; i < d1.length - 1; i++) {
						var did = d1[i].split(":")[0];
						var dname = d1[i].split(":")[1];
 
						document.getElementById("deliver").options
								.add(new Option(dname, did));
					}

					for (j = 0; j < p1.length - 1; j++) {
						var pid = p1[j].split(":")[0];
						var pname = p1[j].split(":")[1];

						document.getElementById("payment").options
								.add(new Option(pname, pid));
					}
				}
    }
    
	function newOpenerCitySelect(cityName) {
	    var Rand = Math.random();
		var ra = (1 + Math.round(Rand * 9999));
		//var timstamp = new Date().valueOf(); 
		 
        var ajax=new Ajax();
        var provinces=document.getElementById("provinces");
        var citys=document.getElementById("citys");
        var provinceName=provinces.options[provinces.selectedIndex].value;
        //var cityName=citys.options[citys.selectedIndex].value;
        ajax.ajaxRequest("${ctx}/addBillManage.do","method=selectCity&vName="+encodeURI(cityName)+"&ra="+ra,'get',newOpenerCitychange);

	
		//$.ajax( {
		//	type :"POST",
		//	url :"addBillManage.do?method=selectCity",
		//	data :"cityName=" + cityName + "&ra" + ra,
		//	success : function(msg) {
//
		//	}
		//}
		//);
	}
	
	function check(){
	//alert("asagasdfhstjw");
		 document.getElementById("needpay").value = document.getElementById("allcashId").value;
		 if(document.getElementById("provinces").value ==""||document.getElementById("provinces").value=="请选择"){
		  alert("请选择省");
		  return false;
		  }
		   if(document.getElementById("citys").value ==""||document.getElementById("citys").value=="请选择"){
		  alert("请选择市");
		  return false;
		  }
		   if(document.getElementById("villages").value ==""||document.getElementById("villages").value=="请选择"){
		  alert("请选择区");
		  return false;
		  }
		   if(document.getElementById("payment").value ==""||document.getElementById("payment").value=="请选择"){
		  alert("请选择付款方式");
		  return false;
		  }
		   if(document.getElementById("deliver").value ==""||document.getElementById("deliver").value=="请选择"){
		  alert("请选择配送方式");
		  return false;
		  }
		  
		  if(document.getElementById("orderindexConsignee").value ==""||document.getElementById("orderindexConsignee").value==null){
		  alert("请输入收货人");
		  return false;
		  }
		   if(document.getElementById("orderindexAddress").value ==""||document.getElementById("orderindexConsignee").value==null){
		  alert("请输入收货人地址");
		  return false;
		  }
		   var postcode = document.getElementById("orderindexPostcode").value;
		  if( postcode==""||postcode==null){
		  alert("请输入收货人邮编");
		  return false;
		  }
		  var pattern = /^[0-9]{6}$/;
                flag = pattern.test(postcode);
                if (!flag) {
                    alert("非法的邮政编码！");

                    return false;
                }
                
           var mobilephone = document.getElementById("orderindexMobilephone").value;     
		  if(mobilephone ==""||mobilephone==null){
		  alert("请输入收货人手机");
		  return false;
		  }
		  
		  
		  var pattern = /^\d+$/  ;
                flag1 = pattern.test(mobilephone);
                if (!flag1) {
                    alert("收货人手机为11位数字！");

                    return false;
                }
           if(mobilephone.length!=11)
           {
            alert("收货人手机为11位数字");
            return false;
           }     
              var email = document.getElementById("orderindexEmail").value;
		  if( email==""||email==null){
		  alert("请输入收货人邮箱");
		  return false;
		  }
		  var pattern = /(\S)+[@]{1}(\S)+[.]{1}(\w)+/;
                flag = pattern.test(email);
                if (!flag) {
                    alert("请填写正确的邮箱！");

                    return false;
                }  
                
                
                var phone = document.getElementById("orderindexPhone").value;
		 if(phone !=null && phone != ''){
		  var pattern = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
                flag = pattern.test(phone);
                if (!flag) {
                    alert("请输入正确的固定电话,如010-63458858或010-63458858-025");

                    return false;
                }			
		}
		
		   
                
		var ta = document.getElementById("PLList");
		var tal = 0;
		for (i = 1; i < ta.rows.length; i++) {
			tal = ta.rows[i].childNodes[6].childNodes[0].value * 1 + tal;			
		}
		var c = window.orderForm.delivercash.value * 1;
		var p = window.orderForm.paypoint1.value * 1;
		var pc = window.orderForm.paycash1.value * 1;
		
		
		if(ta.rows.length==1)	
		{
		alert("至少要添加一个商品");
		return false;
		}
		
		for (j = 1; j < ta.rows.length; j++) {
			var productName = ta.rows[j].childNodes[1].childNodes[1];	
		//	alert(productNamewlekfglhg);
			if(productName!=undefined && productName.value == ""){
				alert("产品名不可以为空");
				return false;
			}
		} 
		
		
		
		if(!tal==0){
	
		if (p > window.orderForm.paypoint.value || p < 0) {
			alert("请输入合理积分");
			return false;
		}
		
		if (pc > window.orderForm.paycash.value || pc < 0) {
			alert("请输入合理滞留金");
			return false;
		}
		if (pc + p > tal) {
			alert("滞留金与积分的总和不得大于总金额");
			return false;
		}
		}
		window.orderForm.allcash.value = tal + c - p - pc;
		
	 	return true;
	}
	
	function newOpenerDeliverChange(){
		var ajax=new Ajax();
		var deliverId = document.getElementById("deliver").value;
		ajax.ajaxRequest("${ctx}/addBillManage.do","method=changeDeliver&deliverId="+deliverId,'get',newOpenerDeliverResult);
	}
	
	
	function newOpenerDeliverResult(price) { 
		if (price != null && price != "NULL") {
		    var tag = document.getElementById("delivercash").value;
			document.getElementById("delivercash").value = price; 	
			document.getElementById("tagdeliver").value = price;		
			
			var pll = document.getElementById("PLList"); 
			for (z = 1; z < pll.rows.length; z++) {
				var tagfd = pll.rows[z].childNodes[4].childNodes[3].value;	 
				if(tagfd == 1){
					document.getElementById("delivercash").value = 0; 
				} else{
					document.getElementById("delivercash").value = document.getElementById("tagdeliver").value;
				}
			}  
			window.orderForm.allcash.value = window.orderForm.allcash.value*1 + document.getElementById("delivercash").value*1 - tag*1;		
		} 
    }
  
  function   checkLen(thiss)  {  
 
  	var   t   =   thiss.value;  
	  if   (t.length   >   255)  {  
	 	 alert("最多可输入255个字");
	        return   false;  
	  }  
  }  
  
                    
  function userEco(){ 
  	 var ecoId = document.getElementById("ecoId").value;
  	 if(ecoId!=""){
  	 	var productId ="";
  	 	var ta = document.getElementById("PLList"); 
		if(ta.rows.length==1){
			alert("至少要添加一个商品");
			return;
		}
		for (j = 1; j < ta.rows.length; j++) {
			var pid = ta.rows[j].childNodes[0].childNodes[1].value;	
			
			if(pid!="" && pid!=0){
		    	productId = productId + pid + ",";
		    }
		}
  	 
  	 
  	 	var ajax=new Ajax();
		var deliverId = document.getElementById("deliver").value;
		
		ajax.ajaxRequest("${ctx}/addBillManage.do","method=useEcoupon&ecouponno="+ecoId+"&productId="+productId,'get',userEcoResult);
  	 
  	 }else{
  	 	alert("请输入优惠卷编号!");
  	 }
  } 
	
  function userEcoResult(str) {
		if(str.indexOf("OK") != -1){
			alert("此优惠卷可以使用");
			var price = str.split(",")[1];
			if(document.getElementById("ecouponPrice").value!="" && document.getElementById("ecouponPrice").value !="0"){
				unuserEco();
			}
			document.getElementById("ecouponPrice").value = price;
			window.orderForm.allcash.value = window.orderForm.allcash.value*1 - price*1;
		}else if(str=="FALSE"){
			alert("此优惠卷不可使用");
		}else{
			alert(str);
		}
  }
  
  function unuserEco(){  
      var price = document.getElementById("ecouponPrice").value;
      
	  window.orderForm.allcash.value = window.orderForm.allcash.value*1 + price*1;
	  document.getElementById("ecouponPrice").value = "";
  }
</script>